package com.zz.ai.func;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zz.ai.util.HttpUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.math.BigDecimal;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.function.Function;

public class HotelUpdateArticleService implements Function<HotelUpdateArticleService.Request, String> {
    private IOException e;

    @Override
    public String apply(HotelUpdateArticleService.Request request) {

        if (request.hotelCode == null){
            return "商品修改缺少酒店代码";
        }

        if (request.pluDescript == null){
            return "商品修改缺少商品描述";
        }

        if (request.skuValue == null){
            return "商品修改缺少商品规格";
        }

        if (request.price == null){
            return "商品修改缺少修改的价格";
        }

        try {
            JSONObject body = new JSONObject();
            body.put("hotelCode",request.hotelCode);
            body.put("pluDescript",request.pluDescript);
            body.put("skuValue",request.skuValue);
            body.put("price",request.price);
            System.out.println(body.toJSONString());
            HttpUtils.getInstance().doPostForBodyString("http://localhost:9081/wposapi/ai/article/updateArticle", body.toJSONString(),new HashMap<>());
        } catch (URISyntaxException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }

        return "修改成功";
    }

    public record Request(String hotelCode, String pluDescript, String skuValue, BigDecimal price) {

    }
}
